package com.csq;

public class Test implements Comparable<Integer>{

     Integer temp;

    public static void main(String[] args) {
//        computer(1000);
//        mp();
        int num [] = new int[]{29, 3, 1, 8, 5, 7, 18, 9, 18 , 19, 90, 34,88,89,0,98};
        Test test = new Test();
        test.insertSort(num);
    }

    /**
     * 插入排序
     */
    public  void insertSort(int [] num){

        for (int i = 1; i < num.length; i ++){
            temp = num[i];
            int j;
            for ( j = i; j > 0 && temp.compareTo(num[j]) < 0; j --){
                //如果当前数小于j，将当前数放在该数的前面
                num[j] = num[j - 1];

            }
            num[j] = temp;
        }

        for(int k : num){
            System.out.print(k + "-");
        }
    }


    /**
     * 冒泡排序
     */
    public static void mp(){
        int num [] = new int[]{29, 3, 1, 8, 5, 7, 18, 9, 18 , 19, 90, 34,88,89,0,98};
        int change = 0;
        for (int i = 0; i < num.length-1; i ++){
            int temp = 0;

            for(int j = i; j < num.length; j ++){
                if (num[i] > num[j]){
                    temp = num[i];
                    num[i] = num[j];
                    num[j] = temp;
                    change ++;
                }
            }
//
            for (int res : num){
                System.out.print(res + "-");
            }
            System.out.println();
        }
        System.out.println(change);


    }

    private static void computer(int num){


        for (int m = 2; m < num; m ++){
            //先计算所有因子的和
            int sum = 0;
            for(int i = 1; i < m; i ++){
                if (m % i == 0){
                    sum += i;
                }
            }

//如果所有因子的和与该数相等
            if(sum == m){
                System.out.print(m + "是完数， 因子为：" );
                for(int j = 2; j < m; j ++){
                    if (m % j == 0){
                        System.out.print(j);
                    }
                }
                System.out.println();
            }

        }




    }



    public int compareTo(Integer o) {
        if (temp - 0 > 0)
            return 1;
        else
        return -1;
    }
}
